<div class="navbar navbar-inverse">
  <div class="container">
    <%= link_to "Samson", root_path, class: "navbar-brand" %>

    <ul class="nav navbar-nav">
      <% if current_user %>
        <li class="dropdown <%= 'active' if request.path.starts_with?('/projects') %>">
          <a href="#" class="dropdown-toggle focus-on" data-focus="#project_search" data-toggle="dropdown">Projects <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li>
              <a class="padding-sm">
                <input id="project_search" type="search" class="filter-list form-control input-block" placeholder="Search projects" data-target=".filtered-projects" data-default="/">
              </a>
            </li>
            <li class="divider"></li>
            <% Project.ordered_for_user(current_user).each do |project| %>
              <li class="filtered-projects">
                <%= link_to project do %>
                  <% starred = current_user.starred_project?(project) %>
                  <span class="glyphicon <%= 'glyphicon-star star starred' if starred %>">
                    <%= '&nbsp;'.html_safe unless starred %>
                  </span>
                  <%= project.name %>
                <% end %>
              </li>
            <% end %>
          </ul>
        </li>
        <% if DeployGroup.enabled? %>
          <li class="dropdown <%= 'active' if request.path.starts_with?('/dashboards') %>">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Environments <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <% Environment.all.each do |env| %>
                <li>
                  <%= link_to dashboard_path(env) do %>
                    <span class="glyphicon">&nbsp;</span> <%= env.name %>
                  <% end %>
                </li>
              <% end %>
            </ul>
          </li>
        <% end %>
        <li class="<%= 'active' if request.path =~ %r{^/deploys[/\?]?$} %>">
          <%= link_to "Deploys", deploys_path %>
        </li>
        <li class="current-deploys <%= 'active' if current_page?(controller: '/deploys', action: 'active') %>" ng-controller="currentDeployBadgeCtrl">
          <%= link_to active_deploys_path do %>
            <%= JobQueue.enabled ? "Deploying" : "Restarting" %>
            <%= content_tag :span, '{{ currentActiveDeploys }}',
                class: 'badge badge-deploys',
                style: 'display: none',
                id: 'currentDeploysBadge',
                data: {count: Deploy.active_count}
            %>
          <% end %>
        </li>
      <% end %>

      <li class="dropdown <%= 'active' if request.path.starts_with?('/admin') %>">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Manage <b class="caret"></b></a>
        <ul class="dropdown-menu">
          <li><%= link_to "Audits", audits_path %></li>
          <li><%= link_to "Builds", Build %></li>
          <% if DeployGroup.enabled? %>
            <li><%= link_to "Environments", environments_path %></li>
            <li><%= link_to "Deploy Groups", deploy_groups_path %></li>
          <% end %>
          <li><%= link_to "Commands", Command %></li>
          <% if current_user.try(:admin?) %>
            <li><%= link_to "Users", users_path %></li>
            <%= Samson::Hooks.render_views(:admin_menu, self) %>
            <li class="divider"></li>
          <% end %>
          <li><%= link_to "Secrets", secrets_path %></li>
          <% if Samson::Secrets::Manager.backend == Samson::Secrets::HashicorpVaultBackend %>
            <li><%= link_to "Vault Servers", vault_servers_path %></li>
          <% end %>
          <li><%= link_to "Reports", csv_exports_path %></li>
          <% if current_user&.super_admin? %>
            <li><%= link_to "OAuth Applications", oauth_applications_path %></li>
          <% end %>
          <%= Samson::Hooks.render_views(:manage_menu, self) %>
        </ul>
      </li>
    </ul>

    <ul class="nav navbar-nav pull-right">
      <% if current_user %>
        <li class="dropdown profile">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            <%= image_tag current_user.gravatar_url, class: "gravatar" %>
            <%= current_user.name %>
            <b class="caret"></b>
          </a>
          <ul class="dropdown-menu">
            <li><%= link_to "Profile", profile_path %></li>
            <li><%= link_to "Access Tokens", access_tokens_path %></li>
            <li><%= link_to "Logout", logout_path %></li>
          </ul>
        </li>
      <% end %>
    </ul>
  </div>
</div>
